﻿using Hotel.BLL;
using Hotel.DAL;
using Hotel.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.Metrics;

namespace Hotel.Server.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MembersController : ControllerBase
    {
       public MembersController( MemberBLL memberBLL) 
        {
            MemberBLL = memberBLL;
        }

        public MemberBLL MemberBLL { get; }







        /// <summary>
        /// 会员增加
        /// </summary>
        /// <param name="info">会员实体</param>
        /// <returns>返回影响的行数</returns>
        [HttpPost]
        public IActionResult MemberAdd( MemberModel info)
        {
            try
            {
                int res = MemberBLL.MemberAdd(info);
                return Ok(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 会员等级的增加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddMemberLevel( MemberLevelModel info)
        {
            try
            {
                int res = MemberBLL.AddMemberLevel(info);
                return Ok(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取会员等级列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult MemberLevelsList()
        {
            try
            {
                var list = MemberBLL.MemberLevelsList();
                return Ok(list);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取会员列表
        /// </summary>
        /// <param name="id">会员编号</param>
        /// <param name="name">会员名称</param>
        /// <param name="levelId">等级名称</param>
        /// <returns></returns>

        [HttpGet]
        public IActionResult MemberList(int? id = null, string? name = "", int? levelId = null)
        {
            try
            {
                //查询所有显示的数据
                var list = MemberBLL.MemberList(id, name, levelId);
                return Ok(list);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 根据id删除会员信息
        /// </summary>
        /// <param name="id">会员id</param>
        /// <returns>返回影响的行数</returns>
        [HttpDelete]
        public IActionResult DelMemeberItem(int id)
        {
            try
            {
                int res = MemberBLL.DelMemeberItem(id);
                return Ok(res);


            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 根据会员id获取会员实体 返填+详情展示
        /// </summary>
        /// <param name="id">会员id</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetMemberInfo(int id)
        {
            try
            {
                //根据id获取会员实体
                var info = MemberBLL.GetMemberInfo(id);
                return Ok(info);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 修改会员
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdatMemberInfo(MemberModel info)
        {
            try
            {
                int res = MemberBLL.UpdatMemberInfo(info);
                return Ok(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }









        /// <summary>
        /// 会员权益添加
        /// </summary>
        /// <param name="memberRight"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult MemberRightAdd(MemberRight memberRight)
        {
          int res= MemberBLL.MemberRightAdd(memberRight);
            return Ok(res);


        }



        /// <summary>
        /// 会员权益显示
        /// </summary>
        /// <param name="count">总条数</param>
        /// <param name="page">总页码</param>
        /// <param name="rightName">名称</param>
        /// <param name="createtiem">时间</param>
        /// <param name="index">页码</param>
        /// <param name="size">页容量</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult MemberRightLiist( string? rightName = "", DateTime? date1 = null, DateTime? date2 = null, int index = 1, int size = 2)
        {

            int count = 0;
            int page = 0;
            List<MemberRight> list = MemberBLL.MemberRightLiist(out count, out page, rightName, date1, date2, index, size);
            return Ok(new { list=list, count = count , page = page });

        }





        /// <summary>
        /// 修改会员权益的状态
        /// </summary>
        /// <param name="id">权益id</param>
        /// <param name="state">状态</param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdateMemberRightState(int id, int state)
        {
            int res = MemberBLL.UpdateMemberRightState(id, state);
           return Ok(res);
        }













    }
}
